home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-15 | 8.2 KB | 370 lines | [TEXT/KAHL] |
- /*
- * Window.c
- *
- * Change History:
- *
- * 4/93 ??? New
- * 4/96 bob Updated #includes to support changed GX Library names.
- * Added the copyright info.
- *
- *
- * © Apple Computer, Inc. 1990 - 1996 All rights reserved
- *
- */
-
-
- #undef MAC_HEADERS
-
-
- /*------------------*/
- /* Include Files */
- /*------------------*/
- #ifndef MAC_HEADERS
- #include <Windows.h>
- #include <Dialogs.h>
- #include <Menus.h>
- #include <ToolUtils.h>
- #endif MAC_HEADERS
-
- #include <GXGraphics.h>
- #include "GraphicsLibraries.h" /* For commonColors */
-
- #include "ResourceIDs.h"
- #include "ShapeAction.h"
- #include "ShapeSetup.h"
-
- #include "Window.h"
-
-
- /*----------------------*/
- /* Global Declarations */
- /*----------------------*/
- GlobalStructure globals;
-
-
- /*------------------------------*/
- /* External Declarations */
- /*------------------------------*/
-
-
- /*------------------------------*/
- /* Local ProtoTypes */
- /*------------------------------*/
- void GetShapePartControls (WindowPtr pWindow, short firstItem, short lastItem, ControlHandle *ph1stControl);
- void TrackCheckBox (ControlHandle hControl, Point where, Boolean *pIsChecked);
- void SetShapePartsFromFlags (GlobalStructure *pG, ControlHandle hControl, long shapeCount);
- void TrackShapePartCheckBox (ControlHandle hControlHit, short whichPart, Point where);
-
-
- void
- GetShapePartControls (WindowPtr pWindow, short firstItem, short lastItem, ControlHandle *ph1stControl)
- {
- register
- short item;
- register
- ControlHandle *pControl;
- short itemType;
- Rect itemRect;
-
- pControl = ph1stControl;
- for (item = firstItem; item <= lastItem; item++)
- {
- GetDItem (pWindow, item, &itemType, (Handle *) pControl, &itemRect);
- if (*pControl == nil)
- {
- DebugStr ("\pGetShapePartControls: No checkbox found");
- break;
- }
- pControl++;
- }
- }
-
-
- Boolean
- InitializeHitTesting (WindowPtr pWindow)
- {
- if (! CreateShapesFrame (pWindow, kRowCount, kColumnCount, &globals.boxes))
- return (false);
-
- if (! CreateHitTestShapes (pWindow, &globals.pShapes, &globals.boxes, kShapeCount))
- return (false);
-
- GetShapePartControls (pWindow, checkBoxFirstShapePart, checkBoxLastShapePart, &globals.hNothing);
-
- /* Force SetShapePartsFromFlags to initialize the shape's shape parts */
- globals.partsHit = gxAnyPart;
- globals.tolerance = 0;
-
- globals.showControlPoints = false;
- globals.showLocalBounds = false;
-
- SetShapePartsFromFlags (&globals, globals.hNothing, kShapeCount);
-
- return (true);
- }
-
-
- void
- CleanupHitTesting (void)
- {
- DisposeHitTestShapes (&globals.pShapes, &globals.boxes);
- }
-
-
- void
- IdleHitTestWindow (WindowPtr pWindow, EventRecord *pEvent)
- {
- Point where;
-
- where = pEvent->where;
- GlobalToLocal (&where);
-
- if (PtInRect (where, &pWindow->portRect))
- UpdateShapePartInfo (&where, &globals);
- }
-
-
- void
- TrackCheckBox (ControlHandle hControl, Point where, Boolean *pIsChecked)
- {
- if (TrackControl (hControl, where, nil))
- {
- *pIsChecked = ! *pIsChecked;
- SetCtlValue (hControl, *pIsChecked);
- }
- }
-
-
- /*
- * pG->hNothing
- * pG->hBounds
- * pG->hAnything
- *
- * pG->(all)Checked
- *
- * pG->partsHit
- */
- /*
- Sets all the shape's shapeParts from the state of the check-boxes
- */
- void
- SetShapePartsFromFlags (GlobalStructure *pG, ControlHandle hControl, long shapeCount)
- {
- register
- gxShape *pShape;
- gxShapePart newParts;
- Boolean *pFlag;
- ControlHandle *pControl;
-
- if (hControl == pG->hNothing)
- {
- if (pG->testNothing)
- {
- /* Nothing checkbox just checked on; turn off all other checkboxes */
- newParts = gxNoPart;
-
- pFlag = &pG->testBounds;
- pControl = &pG->hBounds;
-
- while (pFlag <= &pG->testAnything)
- SetCtlValue (*pControl++, *pFlag++ = false);
- }
- else
- {
- /* Nothing was just checked off; turn on all other checkboxes */
- pFlag = &pG->testBounds;
- pControl = &pG->hBounds;
-
- newParts = gxAnyPart;
- while (pFlag <= &pG->testAnything)
- SetCtlValue (*pControl++, *pFlag++ = true);
-
- SetCtlValue (pG->hNothing, pG->testNothing = false);
- }
- }
- else if (hControl == pG->hAnything)
- {
- Boolean newState;
-
- /* Anything checkbox hit */
- if (pG->testAnything)
- {
- /* Turn on all checkboxes if Anything was already checked */
- newState = true;
- newParts = pG->partsHit | gxAnyPart;
- }
- else
- {
- /* Turn off all checkboxes */
- newState = false;
- newParts = pG->partsHit & ~gxAnyPart;
- }
-
- pFlag = &pG->testBounds;
- pControl = &pG->hBounds;
-
- while (pFlag <= &pG->testPattern)
- SetCtlValue (*pControl++, *pFlag++ = newState);
-
- /* Turn off the Nothing checkbox */
- SetCtlValue (pG->hNothing, pG->testNothing = false);
- }
- else
- {
- /* An individual checkbox was hit */
- newParts = gxNoPart;
-
- if (pG->testNothing)
- SetCtlValue (pG->hNothing, pG->testNothing = false);
- if (pG->testBounds) newParts |= gxBoundsPart;
- if (pG->testGeometry) newParts |= gxGeometryPart;
- if (pG->testPen) newParts |= gxPenPart;
- if (pG->testCornerPoint) newParts |= gxCornerPointPart;
- if (pG->testControlPoint) newParts |= gxControlPointPart;
- if (pG->testEdge) newParts |= gxEdgePart;
- if (pG->testJoin) newParts |= gxJoinPart;
- if (pG->testStartCap) newParts |= gxStartCapPart;
- if (pG->testEndCap) newParts |= gxEndCapPart;
- if (pG->testDash) newParts |= gxDashPart;
- if (pG->testPattern) newParts |= gxPatternPart;
-
- if (pG->testAnything &&
- (newParts & gxAnyPart) != gxAnyPart)
- SetCtlValue (pG->hAnything, pG->testAnything = false);
- }
-
- if (newParts == gxNoPart)
- SetCtlValue (pG->hNothing, pG->testNothing = true);
- else if ((newParts & gxAnyPart) == gxAnyPart &&
- (! pG->testAnything))
- {
- SetCtlValue (pG->hAnything, pG->testAnything = true);
- }
-
- /* Set the new parts tested on all shapes */
- for (pShape = pG->pShapes + shapeCount - 1;
- pShape >= pG->pShapes;
- pShape--)
- {
- GXSetShapeHitTest (*pShape, newParts, pG->tolerance);
- }
- pG->partsHit = newParts;
- }
-
-
- void
- TrackShapePartCheckBox (ControlHandle hControlHit, short whichPart, Point where)
- {
- Rect bounds;
-
- if (hControlHit == globals.hNothing)
- { TrackCheckBox (globals.hNothing, where, &globals.testNothing);
- return;
- }
-
- if (hControlHit == globals.hBounds)
- { TrackCheckBox (globals.hBounds, where, &globals.testBounds);
- return;
- }
-
- if (hControlHit == globals.hGeometry)
- { TrackCheckBox (globals.hGeometry, where, &globals.testGeometry);
- return;
- }
-
- if (hControlHit == globals.hPen)
- { TrackCheckBox (globals.hPen, where, &globals.testPen);
- return;
- }
-
- if (hControlHit == globals.hCornerPoint)
- { TrackCheckBox (globals.hCornerPoint, where, &globals.testCornerPoint);
- return;
- }
-
- if (hControlHit == globals.hControlPoint)
- { TrackCheckBox (globals.hControlPoint, where, &globals.testControlPoint);
- return;
- }
-
- if (hControlHit == globals.hEdge)
- { TrackCheckBox (globals.hEdge, where, &globals.testEdge);
- return;
- }
-
- if (hControlHit == globals.hJoin)
- { TrackCheckBox (globals.hJoin, where, &globals.testJoin);
- return;
- }
-
- if (hControlHit == globals.hStartCap)
- { TrackCheckBox (globals.hStartCap, where, &globals.testStartCap);
- return;
- }
-
- if (hControlHit == globals.hEndCap)
- { TrackCheckBox (globals.hEndCap, where, &globals.testEndCap);
- return;
- }
-
- if (hControlHit == globals.hDash)
- { TrackCheckBox (globals.hDash, where, &globals.testDash);
- return;
- }
-
- if (hControlHit == globals.hPattern)
- { TrackCheckBox (globals.hPattern, where, &globals.testPattern);
- return;
- }
-
- TrackCheckBox (globals.hAnything, where, &globals.testAnything);
- }
-
-
- void
- DoHitTestContent (EventRecord *pEvent, WindowPtr pWindow)
- {
- Point where;
- ControlHandle hControl;
- short partCode;
-
- where = pEvent->where;
- GlobalToLocal (&where);
-
- partCode = FindControl (where, pWindow, &hControl);
-
- if (hControl != nil)
- {
- TrackShapePartCheckBox (hControl, partCode, where);
- SetShapePartsFromFlags (&globals, hControl, kShapeCount);
- }
- }
-
-
- void
- ToggleMetricsMenuItem (short item, WindowPtr pWIndow)
- {
- Boolean *pState;
- Str255 menuItemStr;
-
- switch (item)
- {
- case itemShowControlPoints:
- pState = &globals.showControlPoints;
- break;
-
- case itemShowLocalBounds:
- pState = &globals.showLocalBounds;
- break;
- }
-
- *pState = ! *pState;
- GetIndString (menuItemStr, metricsMenuStringsID, *pState + 2 * item - itemShowControlPoints);
- SetItem (GetMHandle (metricsMenuRsrcID), item, menuItemStr);
-
- if (*pState && item == itemShowControlPoints)
- ShowControlPoints (globals.pShapes, kShapeCount);
- else
- UpdateHitTestWindow (pWIndow);
- }
-